#include<bits/stdc++.h>
using namespace std;

class Solution {
public:

    int numberOfBoomerangs(vector<vector<int>>& points) {
        unordered_map<int, int> mp;
        int n = points.size();
        int temp, ans = 0;
        for(int i = 0; i < n; i++){
            mp.clear();
            for(int j = 0; j < n; j++){
                temp = (points[i][0] - points[j][0]) * (points[i][0] - points[j][0]) + 
                       (points[i][1] - points[j][1]) * (points[i][1] - points[j][1]);
                mp[temp]++;
            }
            unordered_map<int, int> :: iterator it = mp.begin();
            for(; it != mp.end(); it++){
                temp = it->second;
                if(temp > 1)ans += temp * (temp - 1);
            }
        }
        return ans;
    }
};

/**
 * 2021.9.13
 * 要考虑顺序的，只要和某个点距离相等的点都可以拿来计算
 * 有 n 个距离某点相等的点，就在里面随机选两个，考虑顺序
 * 所以是 A(n,2)
 */